var sys = require("util");
var io = require("./node_modules/socket.io");
var express = require("./node_modules/express");
var fs = require("fs");

function log(data) {
	sys.log("\033[0;32m"+data+"\033[0m");
}

var app = express.createServer();
//app.use(express.logger());
app.use("/public", express.static(__dirname + '/public'))
app.listen(8080);
console.log('Express server started on port %s', app.address().port);

app.get('/', function(req, response){
    fs.readFile(__dirname + '/public/index.html', 'utf8', function(err, text){
        response.send(text);
    });
});

app.get('/js/socket.io.js', function(req, response){
    fs.readFile(__dirname + '/public/js/socket.io.js', 'utf8', function(err, text){
        response.send(text);
    });
});

io = io.listen(app);
io.sockets.on('connection', function (socket) {
	log("IO connected");	
  	socket.emit('news', { hello: 'world' });
  	socket.on('my other event', function (data) {
    console.log(data);
  });
});